package com.ayu.wxgzh.ayucyy.Utils;

import com.aliyun.chatbot20171011.Client;
import com.aliyun.chatbot20171011.models.ChatRequest;
import com.aliyun.chatbot20171011.models.ChatResponse;
import com.aliyun.teaopenapi.models.Config;

/**
 * 阿里云-云小蜜智能对话机器人
 */
public class ChatBootUtil {

    // AccessKey ID
    private static final String accessKeyId = "LTAI5tPZcLuuuCpTfvJVVRzR";

    // AccessKey Secret
    private static final String accessKeySecret = "dRa8GEdkQh2aJjDQDDYNwsJ9du9UXz";

    /**
     * 使用AK&SK初始化账号Client
     *
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "chatbot.cn-shanghai.aliyuncs.com";
        return new Client(config);
    }

    /**
     * 对话
     *
     * @param reqMsg
     * @return
     */
    public static ChatResponse chat(String reqMsg) throws Exception {
        Client client = createClient(accessKeyId, accessKeySecret);
        ChatRequest chatRequest = new ChatRequest()
                .setUtterance(reqMsg)
                .setInstanceId("chatbot-cn-vaaqyjbiNe");
        return client.chat(chatRequest);
    }

}

